<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
	<meta charset="UTF-8"/>
	<script type = "text/javascript" ></script>
	<script src='<c:url value="/js/boot.js"></c:url>'></script>
	<script src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
	<script type="text/javascript"	src='<c:url value="/js/ajaxfileupload.js"></c:url>'></script>
	<title>课程基本信息</title>
	<style>
		html,body{
			margin: 0;
			padding: 0;
			font-family: "微软雅黑";
		}
		li{
			list-style: none;
		}
		a{
			text-decoration: none;
		}
		.Basic_course_content{
			width: 1920px;
			width: 100%;
		}
		.Basic_course_content_content{
			width: 100%;
			margin: 0 auto;
		}
		.Basic_course_content_content_content{
			width: 780px;
			margin: 0 auto;
			margin-top: 30px;
			text-align: left;
		}
		.Basic_course_content_content_content_title{
			color: #2459aa;
			font-size: 18px;
			padding-bottom: 5px;
			border-bottom: 1px solid #2459aa;
		}
		.Basic_course_content_content_content_content{
			padding: 25px 0;
		}
		.Basic_course_content_content_content_content>ul>li{
			padding: 16px 0;
		}
		.Basic_course_content_content_content_content>ul{
			margin: 0;
			padding: 0;
			margin-bottom: 16px;
		}
		.Basic_course_content_content_content_content>ul>li>div>span{
			float: left;
			font-size: 16px;
			padding: 4px 0;
		}
		.Basic_course_content_content_content_content>ul>li>div>span>font{
			color: #ff0000;
		}
		.Basic_course_content_content_content_content>ul>li>div>input{
			width: 420px;
			padding: 5px 0;
			padding-left: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>select{
			padding: 5px 0;
			padding-left: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>textarea{
			width: 420px;
			padding: 5px;
    		margin-top: 5px;
		}
		.Basic_course_content_content_content_content>ul>li>div>select>option{
			padding: 3px;
		}
		.Basic_course_baocun{
			background: #2459aa;
			color: #fff;
			font-size: 16px;
			padding: 5px 15px;
			border-radius: 3px;
			margin-left: 92px;
		}
		#TimerDiv{
			position: relative;
			overflow: hidden;
		}
		#TimerDiv>div{
			float: left;
			padding: 2px;
		}
		#TimerDiv>div>table{
			width: 94px;
		}
		#TimerDiv>div>table>tbody>tr>td>input{
			text-align: center;
		}
		#btn_down{
			background: url("<c:url value="/share/images/down.jpg"></c:url>");
		}
		#btn_up{
			background: url("<c:url value="/share/images/up.jpg"></c:url>");
		}
		#Outline_Title>input{
		    width: 530px;
		    padding: 5px 0;
		    margin: 5px 0;
		    padding-left: 5px;
		}
	</style>
</head>
<body>
	<div class="Basic_course_content">
		<div class="Basic_course_content_content">
			<div class="Basic_course_content_content_content">
				<div class="Basic_course_content_content_content_title">
					课程基本信息
				</div>
				<div class="Basic_course_content_content_content_content">
					<ul>
						<li>
							<div>
								<span><font>*</font> 课程名称：</span>
								<input type="text" id = "class_name"/>
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 课程类型：</span>
								<select  id = "select_type"> 
								      
							    </select>
							</div>
						</li>
						<li>
							<div>
								<span><font>*</font> 课程形式：</span>
								<select id = "source_type" > 
								      <option value = "1">图文课程</option> 
								      <option value = "2">音频课程</option> 
								      <option value = "3">视频课程</option> 
							    </select>
							</div>
						</li>
						
						<li id = "selectSource" style="display:none">
							<div><span><font>*</font> 选择资料：</span></div> 
							<input id="lookup" name="look" class="mini-lookup"
							style="width: 432px;height:32px;" textField="source_name" valueField="id"
							popupWidth="auto" popup="#gridPanel" grid="#datagrid"
							multiSelect="true" value=""
							text="" />

							<div id="gridPanel" class="mini-panel" title="header"
								iconCls="icon-add" style="width: 450px; height: 250px;"
								showToolbar="true" showCloseButton="true" showHeader="false"
								bodyStyle="padding:0" borderStyle="border:0">
								<div property="toolbar"
									style="padding: 5px; padding-left: 8px; text-align: center;">
									<div style="float: left; padding-bottom: 2px;">
										<span>资料：</span> <input id="keyText" class="mini-textbox"
											style="width: 160px;" onenter="onSearchClick" /> <a
											class="mini-button" onclick="onSearchClick">查询</a> <a
											class="mini-button" onclick="onClearClick">清除</a>
									</div>
									<div style="float: right; padding-bottom: 2px;">
										<a class="mini-button" onclick="onCloseClick">确定</a>
									</div>
									<div style="clear: both;"></div>
								</div>
								<div id="datagrid" class="mini-datagrid"
									style="width: 100%; height: 100%;" borderStyle="border:0"
									showPageSize="false" showPageIndex="false" multiSelect="false"
									url='' >
									<div property="columns">
										<div type="indexcolumn"></div>
										<div field="source_name" width="120" headerAlign="center"
											allowSort="true">资料名称</div>
										<div field="creater" width="120" headerAlign="center"
											allowSort="true">编制人</div>
										<div field="createTime" width="100" headerAlign="center"
											dateFormat="yyyy-MM-dd" allowSort="true">创建日期</div>
									</div>
								</div>
							</div>
						</li> 
						<li id = "selectPpt" style="display:none">
							<div><span><font>*</font> 选择PPT：</span> </div> 
							<input id="lookup2" name="look2" class="mini-lookup"
							style="width: 432px;height:32px;" textField="source_name" valueField="id"
							popupWidth="auto" popup="#gridPanel2" grid="#datagrid2"
							multiSelect="true" value=""
							text="" />

							<div id="gridPanel2" class="mini-panel" title="header"
								iconCls="icon-add" style="width: 450px; height: 250px;"
								showToolbar="true" showCloseButton="true" showHeader="false"
								bodyStyle="padding:0" borderStyle="border:0">
								<div property="toolbar"
									style="padding: 5px; padding-left: 8px; text-align: center;">
									<div style="float: left; padding-bottom: 2px;">
										<span>ppt：</span> <input id="keyText" class="mini-textbox"
											style="width: 160px;" onenter="onSearchClick2" /> <a
											class="mini-button" onclick="onSearchClick2">查询</a> <a
											class="mini-button" onclick="onClearClick2">清除</a>
									</div>
									<div style="float: right; padding-bottom: 2px;">
										<a class="mini-button" onclick="onCloseClick2">确定</a>
									</div>
									<div style="clear: both;"></div>
								</div>
								<div id="datagrid2" class="mini-datagrid"
									style="width: 100%; height: 100%;" borderStyle="border:0"
									showPageSize="false" showPageIndex="false"
									url='' >
									<div property="columns">
										<div type="indexcolumn"></div>
										<div field="source_name" width="120" headerAlign="center"
											allowSort="true">资料名称</div>
										<div field="creater" width="120" headerAlign="center"
											allowSort="true">编制人</div>
										<div field="createTime" width="100" headerAlign="center"
											dateFormat="yyyy-MM-dd" allowSort="true">上传日期</div>
									</div>
								</div>
							</div>
						</li>
						<li id="GenerateTime" style="display: none;">
							<div>
								  <input type="search" id="NumInt" name="" value="" placeholder="请输入PPT视频个数..." style="width:180px;"  onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')">
								  <button onclick="AddTime()" style="height: 29px;padding: 0 20px;">PPT视频时段生成</button>
								  <div id="TimerDiv">
								  	<div id="timer1"></div>
								  </div>
								  <button id="TimeValue" onclick="TimeValue()" style="height: 29px;padding: 0 20px;display:none;">保存</button>
							</div>
						</li>
						<li id="outline" style="display: none;">
							<div>
								  <input type="search" id="outlineNum" name="" value="" placeholder="请输入大纲个数..." style="width: 180px;" onkeyup="this.value=this.value.replace(/[^0-9]/g,'')" onafterpaste="this.value=this.value.replace(/[^0-9]/g,'')"></input>
								  <button onclick="AddOutline()" style="height: 29px;padding: 0 20px;">PPT大纲生成</button>
								  <div id="OutlineDiv" style="display: none;">
								  	<div id="Outline_Title">
								  	</div>
								  </div>
								  <button id="OutlineValue" onclick="OutlineValue()" style="height: 29px;padding: 0 20px;display:none;">保存</button>
							</div>
						</li>
						<li>
							<div>
								<span><font>&nbsp;</font> 课程封面：</span>
								<input id = "class_photo" accept = "image/jpeg,image/jpg,image/png" name = "photo" type="file" style="border: 1px solid #ccc;" />
							</div>
						</li>
						<li>
							<div class="Basic_course_modify">
								<span><font>*</font> 课程简介：</span>
								<textarea id = "class_con" rows="8" cols="50" placeholder="请填写课程简介"></textarea>
							</div>
						</li>
					</ul>
					<a href="javascript:save();" class="Basic_course_baocun">确定</a>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
	/*
	 *@大纲PPT对应数和title
	*/
	var OutlineContent;//大纲内容
	
	function AddOutline(){
		var html = '';
		var index = $("#outlineNum").val();
		for(var i = 0; i < index; i++){
			html += "<input class='Outline_Num' type='search' style='width: 220px;display: block;' name='' value='' placeholder='请输入大纲对应PPT末置位数...' onkeyup=\"this.value=this.value.replace(/[^0-9]/g,'')\" onafterpaste=\"this.value=this.value.replace(/[^0-9]/g,'')\"></input><input class='Outline_Title' type='search' name='' value='' placeholder='请输入大纲内容...'></input>";
		}
		$("#OutlineDiv").show();
		$("#OutlineValue").show();
		$("#Outline_Title").html(html);
		$("#OutlineValue").show().attr('disabled',false).html('保存');
	}
	
	function OutlineValue(){
		var NumLength = $("#Outline_Title>input.Outline_Num").length;
		var TitleLength = $("#Outline_Title>input.Outline_Title").length;
		var NumValue,TitleValue;
		var OutlineArr = [];
		var SmallArr = [];//从小到大排序存储数组
		var ifArray = 0;
		for(var i = 0; i < NumLength; i++){
			OutlineArr.push([$("#Outline_Title>input.Outline_Num:eq("+ i +")").val(),$("#Outline_Title>input.Outline_Title:eq("+ i +")").val()]);
			SmallArr.push([$("#Outline_Title>input.Outline_Num:eq("+ i +")").val(),$("#Outline_Title>input.Outline_Title:eq("+ i +")").val()]);
		}
		//从小到大排序(二维数组排序)
		SmallArr = SmallArr.sort(function(a,b){return a[0]-b[0]});
		if(OutlineArr.toString() == SmallArr.toString()){
			for(var i = 0; i < NumLength; i++){
				if(SmallArr[i][1] !== ""){
					if(i+1 < NumLength && SmallArr[i][0] == SmallArr[i+1][0]){
						mini.alert("对不起,大纲对应PPT数,不能相等和大纲不能为空");
						ifArray = 1;
						return;
					}
				}else if(SmallArr[i][1] === ""){
					mini.alert("对不起,大纲不能为空");
					ifArray = 1;
					return;
				}
			}
			if(ifArray === 0){
				OutlineContent = OutlineArr;
				$("#OutlineValue").attr('disabled',true).html('保存成功！');
			}
		}else{
			mini.alert("对不起,大纲对应PPT数,后者不能大于前者");
			ifArray = 1;
		}
	}
	
	/*
	   *@作者: 王弘
	   * 时分秒生成器自定义
	   */
	  		//小时
	  		var HH=23;
	  		//分钟
			var MM=59;
			//秒
			var SS=59;
			var mode={};
			var TimeArray = [];
			var LOOP;
			var ssArray;
			//点击次数
			var x=0;

			function TimeValue(){
				TimeArray = [];
				//获取要生成的值
				var val = parseInt(document.getElementById('NumInt').value);
				if(val !== "" && val > 0){
			        for(var i = 1; i < val + 1; i++){
			        	//console.log(i)
					    //getValue('timer'+ i );
					    (function(e) {  
					        setTimeout(function() {  
					        	getValueTime('timer'+ e ); 
					        }, 1000); 
					    })(i); 
			        }
		        }else if(val <= 0){
		        	alert('对不起不能输入小于0或则等于0的数字')
		        }
			}

			//获取时分秒值
			function getValueTime(id){
				returnTimer(id);
			}

			//小时/ 分 /秒 转换
			function TimeTransformation(strHH,strMM,strSS){
			    var v1=0;
			    var v2=0;
			    var v3=0;
			    var v1= parseInt(strHH*60*60);//参数1
			    var v2 = parseInt(strMM*60);  //参数2
			    var v3 = v1 + v2 + parseInt(strSS);  //参数3
			    //return v1+v2+strSS;// 最简单的!
			    TimeArray.push(v3);
			    ssArray = TimeArray;
			    $("#TimeValue").attr('disabled',true).html('保存成功！');
			    $("#TimerDiv table input").attr({
			    	'readonly':'readonly',
			    	'onchange':'',
			    	'onkeydown':'',
			    	'onkeyup':'',
			    	'onfocus':'',
			    	'onmouseup':'',
			    	'onmousedown':''
			    });
			}

			function AddTime(){
				x=x+1;
		        var html = "";
		        var html2 = "";
		        var val = parseInt(document.getElementById('NumInt').value);
		        if(val !== "" && val > 0){
			        for(var i = 1; i < val + 1; i++){
			        	(function(e) {  
					        setTimeout(function() {  
					            showTimer('timer'+ e ,e); 
					        }, 1000); 
					    })(i); 
			        	html += '<div>第'+ i +'个时间段</div>';
			        	html2 += '<div id="timer'+ i +'"></div>';
			        }
			        document.getElementById('TimerDiv').innerHTML = html2;
			        $("#TimeValue").show().attr('disabled',false).html('保存');
		        }else if(val <= 0){
		        	alert('对不起不能输入小于0或则等于0的数字')
		        }
			}
			
			function loopInit(id,sign){
				LOOP=true;				
				change(id,sign);
			}
			function loopBreak(){
				LOOP=false;
			}
			function getTag(id,tagName,str,attr){
					var tagArray=document.getElementById(id).getElementsByTagName(tagName);
					for(var i=0;i<tagArray.length;i++){
							if(eval("tagArray[i]."+attr)==str){
									return tagArray[i];
							}		
					}	
			}
			function setMode(id,hms){
					var selectInputPre = getTag(id,'input',mode[id+"mode"],'name');
					var selectInput = getTag(id,'input',hms,'name');
					selectInputPre.style.backgroundColor="#FFFFFF";
					mode[id+"mode"]=hms;
					selectInput.style.backgroundColor="#7FFFD4";
			}
			function change(id,sign){
					if(LOOP){
						var num=getTag(id,'input',mode[id+"mode"],'name').value-0;
						var changeNum=eval(num+sign+1)+"";
						if(changeNum>=0&changeNum<=eval(mode[id+"mode"])){	
							changeNum=complete(changeNum);
							getTag(id,'input',mode[id+"mode"],'name').value=changeNum;		
						}
						setTimeout("change('"+id+"','"+sign+"')",200);		
					}		
			}
			function complete(num){
					while(!(num.length==2)){
						num="0"+num;	
					}
			return num;		
			}
			function returnTimer(id){
					var strHH=getTag(id,'input','HH','name').value;
					var strMM=getTag(id,'input','MM','name').value;
					var strSS=getTag(id,'input','SS','name').value;
					TimeTransformation(strHH,strMM,strSS);
					//return strHH+':'+strMM+':'+strSS;
			}
			function checkNum(id,sign,value){
				if(value<10){
					value=complete(value);
					getTag(id,'input',sign,'name').value=value;
				}else{
					if(value>eval(sign)){
						getTag(id,'input',sign,'name').value=eval(sign);
					}
				}
			}
			function keyDown(id,key,onFocusObject){
				var nextObject;
				if(onFocusObject.name=='HH'){
					nextObject='MM';
				}else if(onFocusObject.name=='MM'){
					nextObject='SS';
				}else if(onFocusObject.name=='SS'){
					nextObject='HH';
				}
				if(!((key>=48 && key<=57)||(key>=96 && key<=105)||(key==8)||(key==46)||(key>=37 && key<=40))){
					event.returnValue=false;
				}
				if(key==37||key==39){
					getTag(id,'input',nextObject,'name').focus();
				}
				if(key==38){
					loopInit(id,'+');
				}
				if(key==40){
					loopInit(id,'-');
				}				
			}
			function keyUp(key){
				if(key==38||40){
					loopBreak();
				}		
			}
			function showTimer(tempId,i){
					mode[tempId+"mode"] = "HH";
					var timerConent='<table cellpadding="0" cellspacing="0" style="border:#949495 1px solid;table-layout : fixed" >'+
													'<span>PPT第'+ i +'页:</span> <tr style="width:94px;height:20px">'+
														'<td width="94px" style="border:0px;display:block;"><input type="text"  maxlength="2" style="border:0;background:transparent;width:20px;height:20px" name="HH" value="0" onchange="checkNum('+"'"+tempId+"',"+"'HH',"+'this.value)" onkeydown="keyDown('+"'"+tempId+"'"+',event.keyCode,this)" onkeyup="keyUp(event.keyCode)" onfocus="setMode('+"'"+tempId+"','HH'"+')"/><input type="text"  style="border:0;background:transparent;width:6px;" readOnly=true  value=":"/><input type="text"  maxlength="2" style="border:0;background:transparent;width:20px;height:20px" name="MM" value="0" onchange="checkNum('+"'"+tempId+"',"+"'MM',"+'this.value)" onkeydown="keyDown('+"'"+tempId+"'"+',event.keyCode,this)" onkeyup="keyUp(event.keyCode)" onfocus="setMode('+"'"+tempId+"','MM'"+')"/><input type="text"  style="border:0;background:transparent;width:6px"  readOnly=true value=":"/><input type="text"  maxlength="2" style="border:0;background:transparent;width:20px;height:20px" name="SS" value="0" onchange="checkNum('+"'"+tempId+"',"+"'SS',"+'this.value)" onkeydown="keyDown('+"'"+tempId+"'"+',event.keyCode,this)" onkeyup="keyUp(event.keyCode)" onfocus="setMode('+"'"+tempId+"','SS'"+')"/></td>'+
														'<td width="20px" style="border:0px;"><input type="button" hidefocus="true" style=";border-width:2px;display:block;background:url(<c:url value="/share/images/up.jpg"></c:url>);width:20px;height:10px;" onmouseup="loopBreak()" onmousedown="loopInit('+"'"+tempId+"','+'"+')"/><input type="button" hidefocus="true" style="border-width:2px ;background:url(<c:url value="/share/images/down.jpg"></c:url>);width:20px;height:10px;" onmouseup="loopBreak()" onmousedown="loopInit('+"'"+tempId+"','-'"+')"/></td>'+
													'</tr>'+
											  	'</table>';
					document.getElementById(tempId).innerHTML = timerConent;	
			}
	
	
	mini.parse();
	mini_debugger = false;
	var rootPath = '${rootPath}';
	var datagrid = mini.get("datagrid");
	var datagrid2 = mini.get("datagrid2");
	var keyText = mini.get("keyText");
	var keyText2 = mini.get("keyText2");
	var filterHelper = gridFilter();
	var filterHelper2 = gridFilter();
	 var lookup = mini.get("lookup");
	 var lookup2 = mini.get("lookup2");
	//source_type值改变显示不同
	var source_type= 1;
	$("#source_type").change(function(){
		source_type = $("#source_type").val();
		if (source_type == 1) {
			$("#selectSource").hide();
			$("#selectPpt").hide();
			$("#GenerateTime").hide();
			$("#outline").hide();
		}else if(source_type == 3){
			$("#selectSource").show();
			$("#selectPpt").show();
			$("#GenerateTime").show();
			$("#outline").show();
			loadGrid();
			loadGrid2();
		}else if(source_type == 2){
			$("#selectSource").show();
			$("#selectPpt").show();
			$("#GenerateTime").hide();
			$("#outline").hide();
			loadGrid();
			loadGrid2();
		}
	});
	$(function(){
		getTypeList();
		
	})
	
	// miniui lookup
	function onSearchClick(e) {
		var key = keyText.getValue();
		filterHelper.clearFilterData();
		if (key != "") {
			var filterdata = filterHelper.formFilterData("source_name",
					key, '', 'CONTAIN', 'AND');
			filterHelper.addFilterData(filterdata);
		}
		
		loadGrid();
    }
	function loadGrid() {
		var filterData = filterHelper.getFilterData();
		var postData = new Object();
		if (filterData != null || filterData.length > 0) {
			postData.filterdata = mini.encode(filterData);
		}
		var url = "<c:url value='/source/list/' />" + source_type;
		datagrid.load(url);
		datagrid.load(postData);
	}
    function onCloseClick(e) {
        lookup.hidePopup();
    }
    function onClearClick(e) {
        lookup.deselectAll();
        keyText.setValue();
        filterHelper.clearFilterData();
        loadGrid();
    }
	// miniui lookup
	function onSearchClick2(e) {
		var key = keyText.getValue();
		filterHelper.clearFilterData();
		if (key != "") {
			var filterdata = filterHelper.formFilterData("source_name",
					key, '', 'CONTAIN', 'AND');
			filterHelper.addFilterData(filterdata);
		}
		loadGrid2();
    }
	function loadGrid2() {
		var filterData = filterHelper2.getFilterData();
		var postData = new Object();
		if (filterData != null || filterData.length > 0) {
			postData.filterdata = mini.encode(filterData);
		}
		var url = "<c:url value='/source/list/4' />";
		datagrid2.load(url);
		datagrid2.load(postData);
	}
    function onCloseClick2(e) {
        lookup2.hidePopup();
    }
    function onClearClick2(e) {
        lookup2.deselectAll();
        keyText2.setValue();
        filterHelper2.clearFilterData();
        loadGrid2();
    }
	
	function save(){
		var dataMap = new Object;
		var url = rootPath + "/class/course_info_add";
		var class_name = $("#class_name").val();
		var type = $("#source_type").val();
		var class_id = $("#select_type").children('option:selected').val();
		var class_con = $("#class_con").val();
		var class_source = lookup.getValue()+"";
		var class_ppt = lookup2.getValue()+"";
		if(!class_name||!class_name.replace(/\s+/g,"")){
			top.commonTools.showTip("请填写课程名称!", 2);
			return;
		}
		if(class_id == "请选择类型"){
			top.commonTools.showTip("请选择课程类型!", 2);
			return;
		}
		if(type != 1){
			if(!class_source){
				top.commonTools.showTip("请选择课程资料!", 2);
				return;
			}
			if(!class_ppt){
				top.commonTools.showTip("请选择ppt!", 2);
				return;
			}
		}
		if(!class_con||!class_con.replace(/\s+/g,"")){
			top.commonTools.showTip("请填写课程简介!", 2);
			return;
		}
		if(!OutlineContent){
			top.commonTools.showTip("请填写大纲!", 2);
			return;
		}
		dataMap.class_name = class_name;
		dataMap.type = type;
		dataMap.class_id = class_id;
		dataMap.class_source = class_source;
		dataMap.class_ppt = class_ppt;
		dataMap.class_con = class_con;
		dataMap.TimeArrAy = ssArray?ssArray:'[000]';
		dataMap.OutlineContent = OutlineContent;
		var jsonData = JSON.stringify(dataMap);
		$.ajax({
			url:url,
			method:"post",
			dataType:"json",
			data:{'data':jsonData},
			success:function(data){
				if(data){
					parent.type = type;
					parent.course_id = data.oid;
					ajaxFileUpload(data.oid); 
					if(type == 1){
						mini.confirm("添加成功，是否继续编制？", "确定？",
					            function (action) {
					                if (action == "ok") {
										CloseWindow(data.oid);
					                } else {
					                	CloseWindow("cancle");
					                }
									
					            });
					}else{
						alert("添加课程成功。");//这里不要改！这样做为了等待异步执行完成
						//top.commonTools.showTip("添加课程成功。", 1);
	                	CloseWindow("cancle");
					}
				}else{
					top.commonTools.showTip("添加课程失败!", 2);
				}
			}
		});
		
	}
	function getTypeList(){
		var url = rootPath + "/class/typeList";
		$.ajax({
			url:url,
			method:"post",
			dataType:"json",
			data:{},
			success:function(data){
				var htmStr;
				if(data){
					htmStr = "<option>请选择类型</option>";
					for(var i = 0;i<data.length; i++){
							htmStr +="<option value = \""+data[i].id+"\">"+data[i].name+"</option>"
					}
				}
				$("#select_type").html(htmStr);
			},
			error:function(){
				top.commonTools.showTip("获取信息失败！", 2);
			}
			
		});
	}
	function ajaxFileUpload(id) {
		var inputName = "photo";
		var fileTitle = "fileTitle";
		var actionType = "course";
		var actionId = id;
		$.ajaxFileUpload({
			url : rootPath + '/attach/upload/'+inputName+'/'
				+fileTitle+'/'+actionType+'/'+actionId, //用于文件上传的服务器端请求地址
			secureuri : false, //是否需要安全协议，一般设置为false
			fileElementId : 'class_photo', //文件上传域的ID
			dataType : 'json', //返回值类型 一般设置为json
			type : 'json',
			/* data : {
				'inputName' : 'file',
				'fileTitle' : 'fileTitle',
				'actionType' : 'actionType',
				'actionId' : '1',
				'note' : '附件说明'
			}, */
			success : function(data, status){ //服务器成功响应处理函数
				/* $("#img1").attr("src", data.imgurl);
				if (typeof (data.error) != 'undefined') {
					if (data.error != '') {
						alert(data.error);
					} else {
						alert(data.msg);
					}
				} */
			},
			error : function(data, status, e){//服务器响应失败处理函数
				top.commonTools.showTip(e, 2);
			}
		})
		//return false;
	}
	
	
	
	
	
	function CloseWindow(action) {
		if (window.CloseOwnerWindow)
		return window.CloseOwnerWindow(action);
		else
		window.close();
		}

		function onOk() {
		//commitTask();
		}
		function onCancel() {
		CloseWindow("cancel");
		}
	</script>
</body>
</html>
